/*
 * Daniel R Padilla
 *
 * Copyright (c) 2008, Daniel R Padilla
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.databasefacade.create;


import java.sql.Connection;

import org.databasefacade.DatabaseConnectionManager;
import org.databasefacade.DatabaseHelper;
import org.databasefacade.exception.DatabaseFacadeException;
import org.databasefacade.registry.TableRegistry;
import org.databasefacade.table.Table;
import org.databasefacade.translator.DefaultAnsiSqlCreateTable;


public class TableRegistrySynchronizer {
    DefaultAnsiSqlCreateTable tableSynch = new DefaultAnsiSqlCreateTable();

    /**
     * Create all the tables in the table registry
     */
    public void synchRegistryTables(TableRegistry registry, DatabaseHelper helper) throws DatabaseFacadeException {
        try {
            Connection conn = helper.getConnection();

            conn.setAutoCommit(true);
            for (int i = 0; i < registry.size(); i++) {
                Table table = registry.getTable(i);

                // TBD
                //tableSynch.createTable(conn, table);
            }
            if (conn.getAutoCommit() == false) {
                conn.commit();
            }
            conn.close();
        } catch (Exception e) {
            throw new DatabaseFacadeException(e,
                    "Unable to synchronize the table registry.");
        }
    }

}
